package com.csr.csrcheck.controller;

import com.csr.csrcheck.pojo.Shareholder;
import com.csr.csrcheck.pojo.Stock_alteration;
import com.csr.csrcheck.service.ShareholderService;
import com.csr.csrcheck.service.Stock_alterationService;
import com.csr.csrcheck.util.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

@RequestMapping({"stock_alteration"})
@RestController
public class Stock_alterationController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(com.csr.csrcheck.controller.Stock_alterationController.class);

    @Resource
    private Stock_alterationService stock_alterationService;

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    @Resource
    private ShareholderService shareholderService;

    @RequestMapping(path = {"addstock_alteration"}, method = {RequestMethod.POST})
    public JsonResult<Object> addspecialb(Stock_alteration stock_alteration, @RequestParam("change_time") String date) throws ParseException {
        stock_alteration.setChange_time(sdf.parse(date));
        this.stock_alterationService.addStock_alteration(stock_alteration);
        log.info("add================================>approvals"+ stock_alteration);
        return new JsonResult(Integer.valueOf(0), "json");
    }

    @RequestMapping(path = {"listshareholder"}, method = {RequestMethod.POST})
    public JsonResult<List<Shareholder>> listshareholder() {
        List list = this.shareholderService.list();
        return new JsonResult(Integer.valueOf(0), "json", list);
    }

    @RequestMapping(path = {"updatestock_alteration"}, method = {RequestMethod.POST})
    public JsonResult<Void> updatestock_alteration(Stock_alteration stock_alteration) {
        this.stock_alterationService.updateStock_alteration(stock_alteration);
        return new JsonResult(Integer.valueOf(0), "json");
    }

    @RequestMapping(path = {"findStock_alterationByid/{id}"}, method = {RequestMethod.POST})
    public JsonResult<Stock_alteration> findStock_alterationByid(@PathVariable("id") int id) {
        Stock_alteration list = null;
        try {
            list = this.stock_alterationService.findstock_alterationByid(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new JsonResult(Integer.valueOf(0), "json", list);
    }

    @RequestMapping(path = {"deletestock_alteration/{id}"}, method = {RequestMethod.POST})
    public JsonResult<Void> deletestock_alteration(@PathVariable("id") int id) {
        this.stock_alterationService.deletestock_alterationByid(id);
        log.info("+ id");
        return new JsonResult(Integer.valueOf(0), "json");
    }
}
